package org.holynite.fieldmanage.entities

import org.holynite.fieldmanage.types.StorageOperateType

import javax.persistence.CascadeType
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.EnumType
import javax.persistence.Enumerated
import javax.persistence.FetchType
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table
import javax.persistence.Temporal
import javax.persistence.TemporalType
import javax.persistence.Transient
import java.sql.Timestamp

/**
 * Created by midnite on 15/1/5.
 */
@Entity
@Table(name = "storage_record")
class StorageRecord implements Serializable {
	@Id
	@Column(name = "storage_record_serial", nullable = false)
	String storageRecordSerial
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "operate_time")
	Date operateTime
	@Column(name = "commodity_id")
	String commodityId
	@Transient
	Commodity commodity
	@Column(name = "operator")
	String operatorId
	@Transient
	Administrator operator
	@Enumerated(EnumType.STRING)
	@Column(name = "operateType")
	StorageOperateType operateType
	@Column(name = "amount")
	Integer amount

	boolean equals(o) {
		if (this.is(o)) return true
		if (getClass() != o.class) return false

		StorageRecord that = (StorageRecord) o

		if (storageRecordSerial != that.storageRecordSerial) return false

		return true
	}

	int hashCode() {
		return (storageRecordSerial != null ? storageRecordSerial.hashCode() : 0)
	}
}
